package bolangit.test.youbike.records.controller;

import bolangit.test.youbike.exception.MyException;
import bolangit.test.youbike.records.entity.BorrowCarRecords;
import bolangit.test.youbike.records.service.BorrowCarRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wjf
 * @description TODO 若不使用后台跳转页面，则使用RestController
 * @date 2019/1/26 22:54
 */
@Controller
@RequestMapping("/records/borrow/car")
public class BorrowCardRecordsController {

    @Autowired
    private BorrowCarRecordsService bcrService;

    @GetMapping("/{id}")
    @ResponseBody
    public BorrowCarRecords getOneById(@PathVariable("id") Long id) throws Exception{
        // 测试全局异常
        // throw new Exception("在获取用户名字的时候为空");
        return bcrService.selectByPrimaryKey(id);
    }

    @GetMapping("/selectAll")
    @ResponseBody
    public List<BorrowCarRecords> selectAll(BorrowCarRecords bcr){
        return bcrService.selectAll(bcr);
    }

    @DeleteMapping("/del/{id}")
    @ResponseBody
    public int deleteByPrimaryKey(@PathVariable("id") Long id){
        return bcrService.deleteByPrimaryKey(id);
    }

    @PutMapping("/add")
    @ResponseBody
    public int insertSelective(BorrowCarRecords bcr){
        return bcrService.insertSelective(bcr);
    }

    @PostMapping("/upd")
    @ResponseBody
    public int updateByPrimaryKeySelective(BorrowCarRecords bcr){
        return bcrService.updateByPrimaryKeySelective(bcr);
    }

}
